home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 26.zip
/
BS1 part 26
/
C for beginners.adf
/
source
/
dec-conv.c
< prev
next >
Wrap
C/C++ Source or Header
|
1978-01-17
|
713b
|
32 lines
/* dec-conv.c 9.4.2 */
void main()
{
long base, test, help, rest;
int index;
char result[260];
printf("Please input number base!\n");
scanf("%ld", &base);
printf("Input number in decimal system!");
scanf("%ld", &test);
index = 0;
for(rest = test; rest > 0; rest = rest / base)
{
help = rest % base; /* Remainder of Division */
if(help > 9) /* Letter to substitute */
result[index] = help + 'A' - 10;
else
result[index] = help + '0';
index = index + 1;
}
printf("%ld(10) = ", test);
index = index - 1; /* last entry is still unused */
while(index >= 0)
{
printf("%c", result[index]);
index = index - 1;
}
printf("(%ld)\n", base);
}